const testUserListData = [
  { userType: 0, name: 'jhb-天下无敌', id: 'f112254690d2' },
  { userType: 0, name: 'jhb-南宫求败', id: '3cce530be2be' },
  { userType: 0, name: 'jhb-西门吹雪', id: '10e6eb1820a0' },
  { userType: 0, name: 'xyf-宇宙先锋', id: '80ac39f7eb2d' },
  { userType: 0, name: 'xyf-曹操操操', id: '12345678' },
  { userType: 0, name: 'xyf-孙能悟空', id: 'c5ec83dd432e' },
  { userType: 0, name: 'zp-二郎天王', id: '4464c39ab9d3' },
  { userType: 0, name: 'zp-诸葛神怒', id: 'a714329371d2' },
  { userType: 0, name: 'zp-小三儿', id: '553733638d' },
  { userType: 0, name: 'zp-小炎子', id: 'we3447638d' },
  { userType: 0, name: 'test222', id: '570540017227722752' },
  { userType: 0, name: 'webrtc-12345', id: '12345' },
  { userType: 1, name: 'audio-56789', id: '56789' },
  { userType: 1, name: 'audio-123450', id: '123450' },
  { userType: 1, name: 'audio-567890', id: '567890' },
]/*.map(({name, id}) => ({
  name: name + parseInt('' + Math.random() * 100),
  id
}))*/;

const url = '/basics-api/public/pubCommunicationAccount/list'
const option = {method: 'post', headers: {'Content-Type': 'application/json; charset=utf-8'}, body: "{}"}
const getAccount = () => fetch(url, option)
  .then(res => res.json())


this.config = {
  iceServers: [
    {
      username: 'kurento',
      credential: 'kurento',
      // url: 'stun:39.103.237.231:23478?transport=tcp',
      // url: 'stun:39.103.237.231:23478',
      url: 'stun:192.168.1.102:23478',
    },
    {
      username: 'kurento',
      credential: 'kurento',
      // url: 'turn:39.103.237.231:23478?transport=tcp',
      // url: 'turn:39.103.237.231:23478',
      url: 'turn:192.168.1.102:23478',
    },
  ],
  // 39.103.237.231 || localhost
  // server: `wss://${window.location.hostname}:8443`,
  // server: `wss://39.103.237.231:8443`,
  server: `//${window.location.hostname}:8443`,
  // freeice: true,

  testMembers: testUserListData.map(({ id, name, type }) => ({
    userId: id, username: name, userType: type
  })),
  getMembers: async function () {
    const { code, data } = await getAccount()

    if (+code === 0 && Array.isArray(data)) {
      while (data.length) {
        const member = data.pop()
        testUserListData.push({
          id: member.communicationAccount,
          name: member.communicationName,
          userType: member.typeCode === 'znsj',
        })
      }
    }

    const userList = testUserListData.map(({ id, name, type }) => ({
      userId: id, username: name, userType: type
    }))

    config.testMembers = userList

    return userList
  }
}

/*if (typeof process === 'undefined') {
  config.iceServers.push({
    username: 'kurento',
    credential: 'kurento',
    url: `stun:${window.location.hostname}:23478?transport=tcp`,
  })
  config.iceServers.push({
    username: 'kurento',
    credential: 'kurento',
    url: `turn:${window.location.hostname}:23478?transport=tcp`,
  })
}*/
